package com.huas.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        log.info("开始创建Redis模板对象");
        RedisTemplate redisTemplate = new RedisTemplate();
        //设置Redis的连接工厂对象，该工厂对象通过依赖注入和@Bean注解从形参中获取
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //设置Redis Key 的序列化器
        //作用是保证在图形化界面查看key时的样式相同
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        return redisTemplate;
    }
}
